extends ItemData
class_name EquipmentData

##装备等级
@export_range(1, 100) var level: int = 1

##装备品质
@export_enum("普通", "精良", "稀有", "史诗", "传说") var quality: String = "普通"

##装备强化等级
@export_range(0, 20) var strengthen_level: int = 0

##装备部位
@export_enum("武器", "头盔", "防具", "护腿", "靴子") var slot: String = "武器"

##基础攻击力
@export var base_attack: int = 0

##基础防御力
@export var base_defense: int = 0

##基础生命值
@export var base_health: int = 0

##是否已锁定（防止误操作）
@export var is_locked: bool = false

##是否已装备
@export var is_equipped: bool = false
##强化
##当前强化经验
@export var strengthen_exp: int = 0
##强化经验上限
@export var strengthen_exp_max: int = 100

func _init():
    # 设置基础属性
    type = "装备"
    is_stackable = false
    name = ""
    description = ""
    price = 0
    count = 1

# 获取装备完整名称
func get_full_name() -> String:
    var 完整名称 = "[" + quality + "]" + name
    if strengthen_level > 0:
        完整名称 += " +%d" % strengthen_level
    return 完整名称

# 获取装备详细信息
func get_detail() -> String:
    var 详细信息 = """
    品质：%s
    等级：%d
    部位：%s
    强化：+%d
    """ % [quality, level, slot, strengthen_level]
    
    if base_attack > 0:
        详细信息 += "\n攻击力：%d" % (base_attack)
    if base_defense > 0:
        详细信息 += "\n防御力：%d" % (base_defense)
    if base_health > 0:
        详细信息 += "\n生命值：%d" % (base_health)
    
    if is_locked:
        详细信息 += "\n[已锁定]"
    if is_equipped:
        详细信息 += "\n[已装备]"
    
    详细信息 += "\n描述：" + description
    
    return 详细信息

# 强化装备
func strengthen(强化石: StrengthenStone) -> bool:
    if is_locked:
        return false
    
    strengthen_exp += 强化石.strengthen_exp*强化石.count
    ##如果强化经验大于等于强化经验上限，则升级
    if strengthen_exp >= strengthen_exp_max:
        strengthen_exp-=strengthen_exp_max
        strengthen_exp_max+=100
        strengthen_level+=1
        if Ui.炼丹炉数据!=null:
            Ui.炼丹炉装备格子数据=EquipmentRange.强化装备(self,强化石).duplicate(true)
        return true
    else:
        # 强化失败
        if 强化石.can_degrade and strengthen_level > 0:
            strengthen_level -= 1
        elif 强化石.can_destroy:
            # 装备破坏的逻辑
            pass
        return false

# 锁定/解锁装备
func toggle_lock():
    is_locked = !is_locked 
